#include "form2_1.h"
#include "ui_form2_1.h"

Form2_1::Form2_1(Passenger &pass,int t,int quant,Flight &fli,QEventLoop &qel,int c,Widget *las,QWidget *parent)
    :passenger(pass),
    i(t),
    quantity(quant),
    flight(fli),
    eventLoop(qel),
    control(c),
    last(las),
    QWidget(parent),
    ui(new Ui::Form2_1)
{
    ui->setupUi(this);
}

Form2_1::~Form2_1()
{
    delete ui;
}

void Form2_1::on_lineEdit_name_textChanged(const QString &arg1)
{
    string s=arg1.toStdString();
    passenger.name=s;
}


void Form2_1::on_lineEdit_cabinClass_textChanged(const QString &arg1)
{
    int s=arg1.toInt();
    passenger.cabinClass=s;
}


void Form2_1::on_pushButton_clicked()
{
    if(control==1){
        // 将乘客加入已订票乘客列表
        flight.bookedPassengers.push_back(passenger);

        if(i != quantity-1){
            this->close();
        }
        else{
            this->page2_3=new Form2_3;
            connect(this->page2_3,SIGNAL(back()),this->last,SLOT(comeBackToPrev2_3()));
            this->close();
            this->page2_3->show();
        }
    }
    if(control==2){
        // 将乘客加入已订票乘客列表
        flight.bookedPassengers.push_back(passenger);
        this->close();
    }

    if(control==3){
        // 将乘客加入候补乘客队列
        flight.waitingList.push(passenger);

        if(i != quantity-1){
            this->close();
        }
        else{
            this->page2_4_1=new Form2_4_1;
            connect(this->page2_4_1,SIGNAL(back()),this->last,SLOT(comeBackToPrev2_4_1()));
            this->close();
            this->page2_4_1->show();
        }
    }

    //退出事件循环
    eventLoop.quit();
}



